package com.blrs.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blrs.common.annotation.Log;
import com.blrs.common.core.controller.BaseController;
import com.blrs.common.core.domain.AjaxResult;
import com.blrs.common.enums.BusinessType;
import com.blrs.domain.PermissionSetting;
import com.blrs.service.file.IPermissionSettingService;
import com.blrs.common.utils.poi.ExcelUtil;
import com.blrs.common.core.page.TableDataInfo;

/**
 * 内部文件权限设置Controller
 * 
 * @author wangchao
 * @date 2023-12-20
 */
@RestController
@RequestMapping("/file/permission")
public class PermissionSettingController extends BaseController
{
    @Autowired
    private IPermissionSettingService permissionSettingService;

    /**
     * 查询内部文件权限设置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PermissionSetting permissionSetting)
    {
        startPage();
        List<PermissionSetting> list = permissionSettingService.selectPermissionSettingList(permissionSetting);
        return getDataTable(list);
    }

    /**
     * 导出内部文件权限设置列表
     */
    @Log(title = "内部文件权限设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PermissionSetting permissionSetting)
    {
        List<PermissionSetting> list = permissionSettingService.selectPermissionSettingList(permissionSetting);
        ExcelUtil<PermissionSetting> util = new ExcelUtil<PermissionSetting>(PermissionSetting.class);
        util.exportExcel(response, list, "内部文件权限设置数据");
    }

    /**
     * 获取内部文件权限设置详细信息
     */
    @GetMapping(value = "/{permissionId}")
    public AjaxResult getInfo(@PathVariable("permissionId") String permissionId)
    {
        return success(permissionSettingService.selectPermissionSettingByPermissionId(permissionId));
    }

    /**
     * 新增内部文件权限设置
     */
    @Log(title = "内部文件权限设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PermissionSetting permissionSetting)
    {
        return toAjax(permissionSettingService.insertPermissionSetting(permissionSetting));
    }

    /**
     * 修改内部文件权限设置
     */
    @Log(title = "内部文件权限设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PermissionSetting permissionSetting)
    {
        return toAjax(permissionSettingService.updatePermissionSetting(permissionSetting));
    }

    /**
     * 删除内部文件权限设置
     */
    @Log(title = "内部文件权限设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{permissionIds}")
    public AjaxResult remove(@PathVariable String[] permissionIds)
    {
        return toAjax(permissionSettingService.deletePermissionSettingByPermissionIds(permissionIds));
    }
}
